﻿
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using BCCommon;
using System.Text;
using System.Net;
using Microsoft.AspNetCore.Mvc;
using BCDto.Common.Cooperation.WebsiteCooperation;
using BCTMSRESTful.Configs;
using BCService.Utils;
using BCService.Common.Cooperation.WebsiteCooperation;

namespace BCTMSRESTful.Controllers.Management.Cooperation.WebsiteCooperation
{
    /// <summary>
    /// 官网合作留言
    /// </summary>
    [ApiExplorerSettings(GroupName = "Admin")]
    [Route("api/v1/sim/[controller]")]
    public class WebsiteCooperationController : ManagementBaseController
    {
        private readonly IWebsiteCooperationService websiteCooperationService;

        public WebsiteCooperationController(IWebsiteCooperationService websiteCooperationService)
        {
            this.websiteCooperationService = websiteCooperationService;
        }

        #region 添加官网合作留言
        /// <summary>
        ///  添加官网合作留言
        /// </summary>
        /// <param name="requestDto">官网合作留言信息</param>
        /// <response code="201">添加官网合作留言成功</response>
        /// <response code="400">请求参数或输入的数据不正确。</response>
        /// <response code="500">服务器发生错误。</response>
        /// <response code="501">某些功能尚未实现。</response>
        /// <returns></returns>
        [HttpPost]
        [Log("添加官网合作留言")]
        [ProducesResponseType(typeof(WebsiteCooperationDto), 201)]
        public IActionResult Post(
            [FromBody]WebsiteCooperationRequestDto requestDto)
        {
            var result = this.websiteCooperationService.Add(requestDto);
            return StatusCode((int)HttpStatusCode.Created, result);
        }
        #endregion

        #region 修改官网合作留言
        /// <summary>
        ///  修改官网合作留言
        /// </summary>
        /// <param name="websiteCooperationId">官网合作留言</param>
        /// <param name="requestDto">官网合作留言信息</param>
        /// <response code="200">修改官网合作留言成功</response>
        /// <response code="400">请求参数或输入的数据不正确。</response>
        /// <response code="500">服务器发生错误。</response>
        /// <response code="501">某些功能尚未实现。</response>
        /// <returns></returns>
        [HttpPut("{website_cooperation_id}")]
        [Log("修改官网合作留言")]
        [ProducesResponseType(typeof(WebsiteCooperationDto), 200)]
        public IActionResult Put([FromRoute(Name = "website_cooperation_id")]int websiteCooperationId, [FromBody]WebsiteCooperationRequestDto requestDto)
        {
            WebsiteCooperationPutDto putDto = requestDto.As<WebsiteCooperationPutDto>();
            putDto.WebsiteCooperationId = websiteCooperationId;
            return StatusCode((int)HttpStatusCode.OK, this.websiteCooperationService.Update(putDto));
        }
        #endregion

        #region 删除官网合作留言
        /// <summary>
        ///  删除官网合作留言
        /// </summary>
        /// <param name="websiteCooperationId">官网合作留言</param>
        /// <response code="204">删除官网合作留言成功</response>
        /// <response code="400">请求参数或输入的数据不正确。</response>
        /// <response code="500">服务器发生错误。</response>
        /// <response code="501">某些功能尚未实现。</response>
        /// <returns></returns>
        [HttpDelete("{website_cooperation_id}")]
        [Log("删除官网合作留言")]
        [ProducesResponseType(typeof(NoContentResult), 204)]
        public IActionResult Delete([FromRoute(Name = "website_cooperation_id")]int websiteCooperationId)
        {
            this.websiteCooperationService.Delete(websiteCooperationId);
            return StatusCode((int)HttpStatusCode.NoContent);
        }
        #endregion

        #region 获取官网合作留言
        /// <summary>
        ///  获取官网合作留言
        /// </summary>
        /// <param name="websiteCooperationId">官网合作留言</param>
        /// <response code="200">获取官网合作留言</response>
        /// <response code="400">请求参数或输入的数据不正确。</response>
        /// <response code="500">服务器发生错误。</response>
        /// <response code="501">某些功能尚未实现。</response>
        /// <returns></returns>
        [HttpGet("{website_cooperation_id}")]
        [ProducesResponseType(typeof(WebsiteCooperationDto), 200)]
        public IActionResult Get([FromRoute(Name = "website_cooperation_id")]int websiteCooperationId)
        {
            return StatusCode((int)HttpStatusCode.OK, this.websiteCooperationService.Get(websiteCooperationId));
        }
        #endregion

        #region 获取官网合作留言列表
        /// <summary>
        ///  获取官网合作留言列表
        /// </summary>
        /// <response code="200">获取官网合作留言列表</response>
        /// <response code="400">请求参数或输入的数据不正确。</response>
        /// <response code="500">服务器发生错误。</response>
        /// <response code="501">某些功能尚未实现。</response>
        /// <returns></returns>
        [HttpGet]
        [ProducesResponseType(typeof(WebsiteCooperationDto), 200)]
        public IActionResult Get()
        {
            return StatusCode((int)HttpStatusCode.OK, this.websiteCooperationService.GetList());
        }
        #endregion

        #region 获取官网合作留言（分页）
        /// <summary>
        ///  获取官网合作留言（分页）
        /// </summary>
        /// <param name="hasFollowUp">已跟进</param>
        /// <param name="start">开始时间</param>
        /// <param name="end">结束时间</param>
        /// <param name="sortName">排序字段</param>
        /// <param name="ascending">升序</param>
        /// <param name="index">当前页码</param>
        /// <param name="size">当前页大小</param>
        /// <response code="200">获取官网合作留言（分页）</response>
        /// <response code="400">请求参数或输入的数据不正确。</response>
        /// <response code="500">服务器发生错误。</response>
        /// <response code="501">某些功能尚未实现。</response>
        /// <returns></returns>
        [HttpGet("[action]")]
        [ProducesResponseType(typeof(PageableList<WebsiteCooperationDto>), 200)]
        public IActionResult Query(
            [FromQuery(Name = "has_follow_up")]bool? hasFollowUp,
            [FromQuery(Name = "start")]DateTime? start,
            [FromQuery(Name = "end")]DateTime? end,
            [FromQuery(Name = "sort_name")]string sortName,
            [FromQuery(Name = "ascending")]bool? ascending,
            [FromQuery(Name = "index")]int index = 1,
            [FromQuery(Name = "size")]int size = 10)
        {
            return StatusCode((int)HttpStatusCode.OK, this.websiteCooperationService.Query(hasFollowUp,start, end, sortName, ascending, index, size));
        }
        #endregion
    }
}

